<template>
  <div class="user_container">
    <nav-head :title="'我的'" :left_show="false"></nav-head>
    <div class="head">
      <div class="top">
        <div class="headImg">
          <img :src="userInfo.headImg" alt="">
        </div>
        <div class="userInfo">
          <div class="nickName">
            昵称: {{ userInfo.nickName }}
          </div>
          <div class="desction">
            个人简介: {{ userInfo.desction }}
          </div>
        </div>
      </div>
      <div class="tabs">
        <div class="tabsItem">
          <div class="count">
            {{ userInfo.price }}
          </div>
          <div class="name">
            账户(元)
          </div>
        </div>
        <div class="tabsItem">
          <div class="count">
            {{ userInfo.polarBean }}
          </div>
          <div class="name">
            极豆
          </div>
        </div>
        <div class="tabsItem">
          <div class="count">
            {{ userInfo.fans }}
          </div>
          <div class="name">
            粉丝
          </div>
        </div>
        <div class="tabsItem">
          <div class="count">
            {{ userInfo.follow }}
          </div>
          <div class="name">
            关注
          </div>
        </div>
      </div>
    </div>
    <!-- 订单导航 -->
    <div class="order">
      <div class="orderItem">
        <div class="itemImg">
          <img src="../../static/order/obligation.png" alt="">
          <!-- <span v-if="userInfo.obligation > 0">
                        {{userInfo.obligation}}
                    </span> -->
        </div>
        <div class="itemTitle">
          待付款
        </div>
      </div>
      <div class="orderItem">
        <div class="itemImg">
          <img src="../../static/order/delivery.png" alt="">
          <!-- <span v-if="userInfo.delivery > 0">
                        {{userInfo.delivery}}
                    </span> -->
        </div>
        <div class="itemTitle">
          待发货
        </div>
      </div>
      <div class="orderItem">
        <div class="itemImg">
          <img src="../../static/order/received.png" alt="">
          <!-- <span v-if="userInfo.received > 0">
                        {{userInfo.received}}
                    </span> -->
        </div>
        <div class="itemTitle">
          待收货
        </div>
      </div>
      <div class="orderItem">
        <div class="itemImg">
          <img src="../../static/order/assess.png" alt="">
          <!-- <span v-if="userInfo.assess > 0">
                        {{userInfo.assess}}
                    </span> -->
        </div>
        <div class="itemTitle">
          待评价
        </div>
      </div>
      <div class="orderItem">
        <div class="itemImg">
          <img src="../../static/order/all.png" alt="">
        </div>
        <div class="itemTitle">
          全部订单
        </div>
      </div>
    </div>
    <div class="tabList">
      <div class="list">
        <div class="icon">
          <img src="../../static/user/balance.png" alt="">
        </div>
        <div class="title">
          余额明细
        </div>
        <div class="right">

        </div>
      </div>
      <div class="list" @click="$router.push('/PolarList')">
        <div class="icon">
          <img src="../../static/user/gold.png" alt="">
        </div>
        <div class="title">
          极豆明细
        </div>
        <div class="right">

        </div>
      </div>
      <div class="list" @click="$router.push('/Task')">
        <div class="icon">
          <img src="../../static/user/polarBean.png" alt="">
        </div>
        <div class="title">
          赚极豆
        </div>
        <div class="right">

        </div>
      </div>
      <div class="list">
        <div class="icon">
          <img src="../../static/user/release.png" alt="">
        </div>
        <div class="title">
          我的发布
        </div>
        <div class="right">

        </div>
      </div>
      <div class="list">
        <div class="icon">
          <img src="../../static/user/tuck.png" alt="">
        </div>
        <div class="title">
          我的收藏
        </div>
        <div class="right">

        </div>
      </div>
      <div class="list" @click="$router.push('/setUp')">
        <div class="icon">
          <img src="../../static/user/setup.png" alt="">
        </div>
        <div class="title">
          设置
        </div>
        <div class="right">

        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 导入组件 头部导航
import navHead from '@/components/nav-head'
// 导入接口文件
import {
  // 解构出来getUserInfo
  getUserInfo
} from '@/api'
export default {
  data() {
    return {
      // 用户信息
      userInfo: {
        headImg: '',
        nickName: '',
        desction: '',
        price: '-',
        polarBean: '-',
        fans: '-',
        follow: '-'
      }
    }
  },
  methods: {
    // 获取用户信息
    getInfo() {
      getUserInfo().then(res => {
        // console.log(res.data);
        // 判断code 1 成功
        if (res.data.code == 1) {
          // 先更新本地token
          localStorage.setItem('token', res.data.result.token);
          // 更新data里面的 用户信息数据
          this.userInfo = res.data.result;
          // 更新本地存储 localStorage的用户信息
          localStorage.setItem('userInfo',JSON.stringify(this.userInfo)) 
        }
      })
    }
  },
  // 注册组件
  components: {
    navHead
  },
  created() {
    // 获取用户信息
    this.getInfo();

    // console.log(this.$store.state.pro_list);
    console.log(this.$store.getters.count);
  }
}
</script>

<style lang="scss" scoped>
.head {
  padding: 20px 4%;
  height: 38vh;
  padding-top: 44px;
  background-image: linear-gradient(to bottom, rgb(50, 134, 255), rgb(50, 134, 255), rgb(29, 70, 245));

  .top {
    height: 90px;
    display: flex;

    .headImg {
      width: 70px;
      height: 90px;
      border-radius: 50%;
      overflow: hidden;

      img {
        width: 70px;
        height: 70px;
        border-radius: 50%;
        margin-top: 10px;
      }
    }

    .userInfo {
      width: calc(100% - 85px);
      margin-left: 15px;
      height: 50px;
      padding: 20px 0;

      .nickName,
      .desction {
        width: 100%;
        height: 25px;
        line-height: 25px;
        color: #fff;
        text-overflow: ellipsis;
        overflow: hidden;
        white-space: nowrap;
      }

      .nickName {
        font-size: 18px;
      }

      .desction {
        font-size: 12px;
        max-width: 80%;
        width: auto;
        display: inline-block;
        color: #eee;
        border: 0.5px solid #eee;
        height: 19px;
        line-height: 12px;
        padding: 3px 5px;
        margin-top: 5px;
        border-radius: 10px;
      }
    }
  }

  .tabs {
    display: flex;
    justify-content: space-between;
    margin-top: 25px;

    .tabsItem {
      width: 25%;
      text-align: center;
      height: 45px;
      color: #fff;
      opacity: 0.8;

      .count {
        font-size: 20px;
        height: 20px;
        line-height: 20px;
      }

      .name {
        font-size: 12px;
        height: 15px;
        margin-top: 5px;
        line-height: 15px;
      }
    }
  }
}

.order {
  width: 95%;
  padding: 15px 2.5%;
  background-color: #fff;
  position: relative;
  top: -40px;
  left: 2.5%;
  border-radius: 7px;
  box-shadow: 0 0 8px 0 rgb(50, 134, 255);
  display: flex;
  justify-content: space-between;

  .orderItem {
    width: 20%;
    text-align: center;

    .itemImg {
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;

      img {
        height: 30px;
      }

      span {
        position: absolute;
        width: 16px;
        height: 16px;
        text-align: center;
        line-height: 16px;
        background-color: red;
        color: #fff;
        border-radius: 50%;
        right: 13px;
        top: 0;
        font-size: 12px;
      }
    }

    .itemTitle {
      height: 20px;
      line-height: 25px;
      font-size: 13px;
      opacity: 0.9;
    }
  }
}

.tabList {
  width: 100%;
  position: relative;
  top: -20px;

  .list {
    width: 95%;
    height: 44px;
    line-height: 34px;
    padding: 5px 2.5%;
    background-color: #fff;
    border-radius: 5px;
    margin-left: 2.5%;
    display: flex;

    .icon {
      width: 42px;
      height: 34px;
      display: flex;
      justify-content: start;
      align-items: center;

      img {
        height: 28px;
      }
    }

    .title {
      width: calc(90% - 42px);
      font-size: 13px;
      opacity: 0.9;
    }

    .right {
      width: 10%;
      position: relative;

      &::after {
        position: absolute;
        width: 7px;
        height: 7px;
        content: '';
        border-bottom: 1px solid #999;
        border-right: 1px solid #999;
        transform: rotate(-45deg);
        top: 14px;
        right: 0;
      }
    }
  }
}</style>